package com.cakebackoffice.clientsoap;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import com.cakebackoffice.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Marjorie
 * Date: 22/03/12
 * Time: 21:51
 * To change this template use File | Settings | File Templates.
 */
public class TestActivity extends ListActivity {
    List<SoapTest> tests = new ArrayList<SoapTest>();

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TestAsyncTask testAsyncTask = new TestAsyncTask(this);
        /** Test : donner le tableau de methodes à tester  */
        testAsyncTask.execute((new CakeBackOfficeSoapClient()).methodArray);

    }

    private class TestAsyncTask extends AsyncTask<Method, Integer, Boolean> {
        ProgressDialog progressDialog;
        Context context;

        public TestAsyncTask(Context context) {
            this.context = context;

        }

        public Context getContext() {
            return context;
        }


        @Override
        protected Boolean doInBackground(Method... methods) {
            for (Method m : methods) {
                if (m != null)
                    tests.add(new SoapTest(m, null));
            }
            return true;
        }

        @Override
        protected void onPreExecute() {
            progressDialog = ProgressDialog.show(getContext(), "Module de Test", "Test en cours ...");
        }

        @Override
        protected void onPostExecute(Boolean bool) {
            progressDialog.dismiss();
            TestActivity.this.setListAdapter(new TestAdapter(getContext(), R.layout.item_testadapter, TestActivity.this.tests));
        }
    }
}